package cn.bgs.controller;

import cn.bgs.pojo.commodity;
import cn.bgs.pojo.itemUser;
import cn.bgs.service.commodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ProjectName: bei
 * @Package: cn.bgs.controller
 * @ClassName: CommodityController
 * @Author: Administrator
 * @Description:
 * @Date: 2021/9/14 0014 8:31
 * @Version: 1.0
 */
@Controller
public class CommodityController {
    @Autowired
    private commodityService commodityService;
    @RequestMapping("/findGoods")
    public String findGoods(Model m,HttpSession s){
        List<commodity> list = commodityService.findGoods();
        for(int i=0;i<list.size();i++){
            list.get(i).setItemNum(1);
        }
        m.addAttribute("list",list);
        return "goods1";
    }
    @RequestMapping("/findShop")
    public String findShop(String id,HttpSession s){

        String stuId =  (String) s.getAttribute("stuId");
        itemUser user = commodityService.selOneUser(id,stuId);
        return "redirect:/findGoods";
    }
    @RequestMapping("/itemUserFind")
    public String itemUserFind(Model m){
        List<itemUser> itemUsers = commodityService.itemUserFind();
        m.addAttribute("list",itemUsers);
        return "shop1";
    }
}
